﻿namespace TestApp.Tests
{
    using System.Collections.Generic;
    using System.Linq;
    using Contracts;
    using DataService;
    using NUnit.Framework;
    using Shouldly;

    [TestFixture]
    internal class DataStoreFixture
    {
        private DataEntityDto _entity0;
        private DataEntityDto _entity1;
        private DataEntityDto _entity2;

        [SetUp]
        public void SetUp()
        {
            _entity0 = new DataEntityDto(0);
            _entity1 = new DataEntityDto(1);
            _entity2 = new DataEntityDto(2);
        }

        [Test]
        public void ShouldSaveDataEntity()
        {
            // Given
            var target = CreateInstance();

            // When
            target.SaveDataEntity(new DataEntityDto(2));
            long curVersion;
            IEnumerable<DataEntityDto> entities;
            target.TryGetDataEntities(0, out curVersion, out entities);

            // Then
            curVersion.ShouldBe(1);
            var entitiesArr = entities.ToArray();
            entitiesArr.Length.ShouldBe(1);
            entitiesArr[0].Index.ShouldBe(2);
        }

        private IDataStore CreateInstance()
        {
            return new DataStore();
        }
    }
}
